**************************************************************
** title:		How Group Appeals Shape Candidate Support 	**
** purpose: 	replication Study 2							**
** date:		march 2025 									**
** machine:		macOS Sonoma 14.4							**
** software:	Stata 18.0 									**	
**************************************************************


* --------------
* preamble
* --------------

	** install packages (if note installed yet)
	*ssc install mplotoffset

	** set working directory first (modify to your directory)
	cd "~/dropbox/symbolic group appeals project/replication materials/data"

	** load dataset	
	use  "study2-coded.dta", clear	
	
	** set working directory for saving tables and figures (modify to your directory)
	cd "~/dropbox/symbolic group appeals project/replication materials/tables and figures"
	
	** set style for graphs
	grstyle init
	grstyle set plain, nogrid noextend		
	
	
* --------------------------
* main results, figure 2
* --------------------------		
		
	** (a) working class
	eststo m1: reg CandidateWorkingVignette i.WorkingGroup##i.WorkingVignetteTreatment i.LabourVignette2 i.SuccesAttention

	margins, dydx(WorkingVignetteTreatment ) at(WorkingGroup=(0 1))
	mplotoffset, offset(0.15) recast(scatter) recastci(rspike) xtitle("") xlabel(0 "Not working class" 1 "Working class") title("") ytitle("AME assignment to working class appeal") ylabel(-1(1)3) legend( nobox cols(2) pos(6) region(col(white))) xsize(3.5) ysize(2) scale(1.5)  yline(0, lpattern(dash)) saving(workControl-small.gph, replace)

	** (b) rural
	eststo m2: reg CandidateRuralVignette i.RuralGroup##i.RuralVignetteTreatment i.LabourVignette3 i.SuccesAttention

	margins, dydx(RuralVignetteTreatment) at(RuralGroup=(0 1))
	mplotoffset, offset(0.15) recast(scatter) recastci(rspike) xtitle("") xlabel(0 "Not in rural area" 1 "Rural area") title("") ytitle("AME assignment to rural appeal") ylabel(-1(1)3) legend( nobox cols(2) pos(6) region(col(white))) xsize(3.5) ysize(2) scale(1.5) yline(0, lpattern(dash)) saving(ruralControl-small.gph, replace)  

	** (c) non-university degree
eststo m3: reg CandidateNonunivVignette i.EducationGroup##i.NonunivVignetteTreatment i.LabourVignette4 i.SuccesAttention

	margins, dydx(NonunivVignetteTreatment) at(EducationGroup=(0 1))
	mplotoffset, offset(0.15) recast(scatter) recastci(rspike) xtitle("") xlabel(0 "University degree" 1 "Non University degree") title("") ytitle("AME assignment to non university appeal") ylabel(-1(1)3) legend( nobox cols(2) pos(6) region(col(white))) xsize(3.5) ysize(2) scale(1.5)  yline(0, lpattern(dash)) saving(nonunivControl-small.gph, replace) 
	
	** (d) women
	eststo m4: reg CandidateWomenVignette i.WomenGroup##i.WomenVignetteTreatment i.LabourVignette5 i.SuccesAttention

	margins, dydx(WomenVignetteTreatment) at(WomenGroup=(0 1))
	mplotoffset, offset(0.15) recast(scatter) recastci(rspike) xtitle("") xlabel(0 "Not a woman" 1 "Woman") title("") ytitle("AME assignment to women appeal") ylabel(-1(1)3) legend( nobox cols(2) pos(6) region(col(white))) xsize(3.5) ysize(2) scale(1.5)  yline(0, lpattern(dash)) saving(womenControl-small.gph, replace)
		
	** (e) elderly
	eststo m5: reg CandidateElderlyVignette i.OldGroup##i.ElderlyVignetteTreatment i.LabourVignette6 i.SuccesAttention

	margins, dydx(ElderlyVignetteTreatment) at(OldGroup=(0 1))
	mplotoffset, offset(0.15) recast(scatter) recastci(rspike) xtitle("") xlabel(0 "64 years or younger" 1 "65+ years") title("") ytitle("AME assignment to elderly appeal") ylabel(-1(1)3) legend( nobox cols(2) pos(6) region(col(white))) xsize(3.5) ysize(2) scale(1.5)  yline(0, lpattern(dash)) saving(elderlyControl-small.gph, replace)
	
	** (f) ethnic minorities
	eststo m6: reg CandidateEthnicVignette i.EthnicGroup##i.EthnicVignetteTreatment i.LabourVignette7 i.SuccesAttention

	margins, dydx(EthnicVignetteTreatment) at(EthnicGroup=(0 1))
	mplotoffset, offset(0.15) recast(scatter) recastci(rspike) xtitle("") xlabel(0 "No ethnic minority" 1 "Ethnic minority") title("") ytitle("AME assignment to ethnic appeal") ylabel(-1(1)3) legend( nobox cols(2) pos(6) region(col(white))) xsize(3.5) ysize(2) scale(1.5)  yline(0, lpattern(dash)) saving(ethnicControl-small.gph, replace)	
	
* -----------------------------	
* appendix I, descriptives
* -----------------------------

	** descriptives identity strength
	la var ImportanceClass "Importance class"
	la var ImportanceEthnicity "Importance ethnic or racial background"
	la var ImportancePlace "Importance place of living"
	la var ImportanceGender "Importance gender"
	la var ImportanceAge "Importance age group"
	la var ImportanceEducation "Importance educational background"
	
	file open anyname using "appendixItable1.txt", write text replace 
	file write anyname  _newline  _col(0)  "\begin{table} [htbp] \centering \caption{Descriptives for identity strength measures, Study 2 \label{tab:descriptives_idstrength}} \footnotesize \begin{tabular}{l*{6}{c}}\toprule "
	file write anyname _newline _col(0) "&Mean & SD & Min & Median & Max & n\\ \midrule"
	foreach x of var  ImportanceClass ImportanceEthnicity ImportancePlace ImportanceGender ImportanceAge ImportanceEducation {
	su  `x' , d
	file write anyname  _newline  _col(0) (`"`: var label `x''"') "&" _col(25) %9.2f  (r(mean)) " &" _col(45) %9.2f  (r(sd)) " &" _col(65) %9.2f  (r(min)) " &"   _col(85) %9.2f  (r(p50)) " &" _col(105) %9.2f  (r(max)) " &" _col(125) %9.0f  (r(N)) " \\"
}
	file write anyname _newline _col(0) "\bottomrule"
	file write anyname _newline _col(0) "\end{tabular}"
	file write anyname _newline _col(0) "\end{table}"
	file close anyname
	
	** descriptives deservingness
	la var UndeservingWorkingClass "Working class has better life conditions than they deserve"
	la var UndeservingUpperMiddleClass "Upper middle class has better life conditions than they deserve"
	la var UndeservingRural "People in rural areas/small towns have better life conditions than they deserve"
	la var UndeservingCities "People in big cities have better life conditions than they deserve"
	la var UndeservingNonuniv "People without a university degree have better life conditions than they deserve" 
	la var UndeservingWomen "Women have better life conditions than they deserve"
	la var UndeservingElderly "The elderly have better life conditions than they deserve"
	la var UndeservingYoung "Young people have better life conditions than they deserve"
	la var UndeservingEthnic "Ethnic minorities have better life conditions than they deserve"
	la var UndeservingUniv "University graduates have better life conditions than they deserve"
	
	file open anyname using "appendixItable2.txt", write text replace 
	file write anyname  _newline  _col(0)  "\begin{table} [htbp] \centering \caption{Descriptives for perceptions of deservingness measures, Study 2 \label{tab:descriptives_deserving}} \footnotesize \begin{tabular}{l*{6}{c}}\toprule "
	file write anyname _newline _col(0) "&Mean & SD & Min & Median & Max & n\\ \midrule"
	foreach x of var  UndeservingWorkingClass UndeservingUpperMiddleClass UndeservingRural UndeservingCities UndeservingNonuniv UndeservingWomen UndeservingElderly UndeservingYoung UndeservingEthnic UndeservingUniv {
	su  `x' , d
	file write anyname  _newline  _col(0) (`"`: var label `x''"') "&" _col(25) %9.2f  (r(mean)) " &" _col(45) %9.2f  (r(sd)) " &" _col(65) %9.2f  (r(min)) " &"   _col(85) %9.2f  (r(p50)) " &" _col(105) %9.2f  (r(max)) " &" _col(125) %9.0f  (r(N)) " \\"
}
	file write anyname _newline _col(0) "\bottomrule"
	file write anyname _newline _col(0) "\end{tabular}"
	file write anyname _newline _col(0) "\end{table}"
	file close anyname
	
* ---------------------------------	
* appendix J, detailed estimates
* ---------------------------------	

	esttab m1 m2 m3 m4 m5 m6 using appendixJtable.tex , b(3) se(3) nogap r2 replace	
	
* ---------------------------------
* stacked analysis prepare data
* ---------------------------------		
		
	** prepare data for stacking
	* DV: candidate evaluation
	gen Candidate1=CandidateControl 
	gen Candidate2=CandidateWorking 
	gen Candidate3=CandidateRural 
	gen Candidate4=CandidateNonuniv 
	gen Candidate5=CandidateWomen 
	gen Candidate6=CandidateElderly 
	gen Candidate7=CandidateEthnic 
	gen Candidate8=CandidateBroad

	gen CandidateAll2=Candidate2						// candidate evaluations for control group are repeated
	replace CandidateAll2=Candidate1 if Candidate2==.	

	gen CandidateAll3=Candidate3						// candidate evaluations for control group are repeated
	replace CandidateAll3=Candidate1 if Candidate3==.	

	gen CandidateAll4=Candidate4						// candidate evaluations for control group are repeated
	replace CandidateAll4=Candidate1 if Candidate4==.	

	gen CandidateAll5=Candidate5						// candidate evaluations for control group are repeated
	replace CandidateAll5=Candidate1 if Candidate5==.	

	gen CandidateAll6=Candidate6						// candidate evaluations for control group are repeated
	replace CandidateAll6=Candidate1 if Candidate6==.	

	gen CandidateAll7=Candidate7						// candidate evaluations for control group are repeated
	replace CandidateAll7=Candidate1 if Candidate7==.	

	gen CandidateAll8=Candidate8						// candidate evaluations for control group are repeated
	replace CandidateAll8=Candidate1 if Candidate8==.	

	* IV: treatment assignment
	gen Vignette1=1 if arm_treatment==1
	replace Vignette1=0 if arm_treatment==2
	gen Vignette2=WorkingVignetteTreatment 
	gen Vignette3=RuralVignetteTreatment 
	gen Vignette4=NonunivVignetteTreatment 
	gen Vignette5=WomenVignetteTreatment 
	gen Vignette6=ElderlyVignetteTreatment 
	gen Vignette7=EthnicVignetteTreatment 
	gen Vignette8=BroadVignetteTreatment

	* IV: ingroup membership
	gen Ingroup2=WorkingGroup
	gen Ingroup3=RuralGroup
	gen Ingroup4=EducationGroup
	gen Ingroup5=WomenGroup
	gen Ingroup6=OldGroup
	gen Ingroup7=EthnicGroup

	* Moderator 1: identity strength
	gen Importance2=ImportanceClass
	gen Importance3=ImportancePlace
	gen Importance4=ImportanceEducation
	gen Importance5=ImportanceGender
	gen Importance6=ImportanceAge
	gen Importance7=ImportanceEthnicity

	* Moderator 2: deservingness perception
	gen Undeserving2=UndeservingWorkingClass
	gen Undeserving3=UndeservingRural
	gen Undeserving4=UndeservingNonuniv
	gen Undeserving5=UndeservingWomen
	gen Undeserving6=UndeservingElderly
	gen Undeserving7=UndeservingEthnic

	* Alternative mechanism: affect
	gen LikeGroup2=LikeWorkingClass
	gen LikeGroup3=LikeRural
	gen LikeGroup4=LikeNonuniv
	gen LikeGroup5=LikeWomen
	gen LikeGroup6=LikeElderly
	gen LikeGroup7=LikeEthnic


	** reshape data in long format
	reshape long Candidate CandidateAll Vignette Ingroup Importance Undeserving LikeGroup OrderVignette LabourVignette, i(caseid) j(number)  

	** code additional variables
	gen appeal=1 if arm_treatment==2		// assigned to an appeal
	replace appeal=0 if arm_treatment==1	// assigned to control

	gen SharedPartisan=0			
	replace SharedPartisan=1 if LabourVignette==1 & profile_partyid==2	// labour partisans
	replace SharedPartisan=1 if LabourVignette==0 & profile_partyid==1	// conservative partisans 

	gen PID3groups=0 if profile_partyid==6								// non-partisan 
	replace PID3groups=1 if SharedPartisan==1							// partisan candidate's party
	replace PID3groups=2 if SharedPartisan!=1 & profile_partyid<=5		// partisan other party

	gen Deserving=0 if Undeserving==10
	replace Deserving=1 if Undeserving==9
	replace Deserving=2 if Undeserving==8
	replace Deserving=3 if Undeserving==7
	replace Deserving=4 if Undeserving==6
	replace Deserving=5 if Undeserving==5
	replace Deserving=6 if Undeserving==4
	replace Deserving=7 if Undeserving==3
	replace Deserving=8 if Undeserving==2
	replace Deserving=9 if Undeserving==1
	replace Deserving=10 if Undeserving==0
	
	
* --------------------------------	
* appendix K, pooled estimates
* --------------------------------

	eststo m1: reg CandidateAll i.Ingroup##i.appeal LabourVignette SuccesAttention,  cluster(caseid)
	eststo m2: reg CandidateAll i.Ingroup##i.appeal SharedPartisan SuccesAttention,  cluster(caseid)
	
	esttab m1 m2 using appendixKtable.tex, b(3) se(3) r2 nogap  replace	
	
	
* ------------------------	
* main results, figure 3
* ------------------------	

	** estimation and marginal effects plot
	eststo m1: reg CandidateAll i.Ingroup##appeal##c.Importance LabourVignette SuccesAttention, cluster(caseid)
	
	margins, dydx(appeal) at(Ingroup=(0) Importance=(0(1)10))
	mplotoffset, offset(0.0) recast(line) recastci(rarea) xtitle("Identity strength")  title("") ytitle("AME assignment to group appeal") ylabel(-2(1)2) ///
	addplot(hist Importance if Ingroup==0, percent bin(10) yaxis(2) yscale(axis(2) alt  ) yscale(range(0(10)150) axis(2)) ///
		 ytitle("Percentage of observations", axis(2)) ) legend(off) ///
		 legend( nobox cols(1) ring(0) bplacement(ne) region(col(white))) yline(0, lpattern(dash)) ciopt(color(gs14) alwidth(none)) ci1opt(color(gs5) alwidth(none)) xlabel(0(2)10) xsize(4) ysize(4) title("") saving(PooledImportanceOutgroup.gph, replace)
	
	margins, dydx(appeal) at(Ingroup=(1) Importance=(0(1)10))
	mplotoffset, offset(0.0) recast(line) recastci(rarea) xtitle("Identity strength")  title("") ytitle("AME assignment to group appeal")  ylabel(-2(1)2) ///
	addplot(hist Importance if Ingroup==1, percent bin(10) yaxis(2) yscale(axis(2) alt  ) yscale(range(0(10)150) axis(2)) ///
		 ytitle("Percentage of observations", axis(2)) ) legend(off) ///
		 legend( nobox cols(1) ring(0) bplacement(ne) region(col(white))) yline(0, lpattern(dash)) ciopt(color(gs14) alwidth(none)) ///
		 ci1opt(color(gs5) alwidth(none)) xlabel(0(2)10) xsize(4) ysize(4) title("") saving(PooledImportanceIngroup.gph, replace)
	
	** table with detailed estimates
	esttab m1  using appendixLtable.tex, b(3) se(3) r2 nogap  replace

	
* ------------------------	
* main results, figure 4
* ------------------------	

	** estimation and marginal effects plot	
	eststo m1: reg CandidateAll i.Ingroup##appeal##c.Deserving LabourVignette SuccesAttention, cluster(caseid)
	
	margins, dydx(appeal) at(Ingroup=(0) Deserving=(0(1)10))
	mplotoffset, offset(0.0) recast(line) recastci(rarea) xtitle("Group is deserving")  title("") ytitle("AME assignment to group appeal") ylabel(-3(1)3) ///
	addplot(hist Deserving if Ingroup==0, percent bin(10) yaxis(2) yscale(axis(2) alt  ) yscale(range(0(10)150) axis(2)) ///
		 ytitle("Percentage of observations", axis(2)) ) legend(off) ///
		 legend( nobox cols(1) ring(0) bplacement(ne) region(col(white))) yline(0, lpattern(dash)) ciopt(color(gs14) alwidth(none)) ci1opt(color(gs5) alwidth(none)) xlabel(0(2)10) xsize(4) ysize(4) title("") saving(PooledDeservingOutgroup.gph, replace)
	
	margins, dydx(appeal) at(Ingroup=(1) Deserving=(0(1)10))
	mplotoffset, offset(0.0) recast(line) recastci(rarea) xtitle("Group is deserving")  title("") ytitle("AME assignment to group appeal") ylabel(-3(1)3) ///
	addplot(hist Deserving if Ingroup==1, percent bin(10) yaxis(2) yscale(axis(2) alt  ) yscale(range(0(10)150) axis(2)) ///
		 ytitle("Percentage of observations", axis(2)) ) legend(off) ///
		 legend( nobox cols(1) ring(0) bplacement(ne) region(col(white))) yline(0, lpattern(dash)) ciopt(color(gs14) alwidth(none)) ci1opt(color(gs5) alwidth(none)) xlabel(0(2)10) xsize(4) ysize(4) title("")  saving(PooledDeservingIngroup.gph, replace)	

	** table with detailed estimates
	esttab m1 using appendixMtable.tex, b(3) se(3) r2 nogap  replace
	
	
* ---------------------------------------------------------	
* appendix N and O, ID strength/deservingness by vignette
* ---------------------------------------------------------	

	** set working directory first
	cd "~/dropbox/symbolic group appeals project/replication materials/data"
	
	** load data
	use "study2-coded.dta", clear
	
	** set working directory for saving graphs and tables
	cd "~/dropbox/symbolic group appeals project/replication materials/tables and figures"
	
	** variable coding 
	** reverse undeservingness measures
	gen DeservingWorkingclass=0 if UndeservingWorkingClass==10
	replace DeservingWorkingclass=1 if UndeservingWorkingClass==9
	replace DeservingWorkingclass=2 if UndeservingWorkingClass==8
	replace DeservingWorkingclass=3 if UndeservingWorkingClass==7
	replace DeservingWorkingclass=4 if UndeservingWorkingClass==6
	replace DeservingWorkingclass=5 if UndeservingWorkingClass==5
	replace DeservingWorkingclass=6 if UndeservingWorkingClass==4
	replace DeservingWorkingclass=7 if UndeservingWorkingClass==3
	replace DeservingWorkingclass=8 if UndeservingWorkingClass==2
	replace DeservingWorkingclass=9 if UndeservingWorkingClass==1
	replace DeservingWorkingclass=10 if UndeservingWorkingClass==0

	gen DeservingRural=0 if UndeservingRural==10
	replace DeservingRural=1 if UndeservingRural==9
	replace DeservingRural=2 if UndeservingRural==8
	replace DeservingRural=3 if UndeservingRural==7
	replace DeservingRural=4 if UndeservingRural==6
	replace DeservingRural=5 if UndeservingRural==5
	replace DeservingRural=6 if UndeservingRural==4
	replace DeservingRural=7 if UndeservingRural==3
	replace DeservingRural=8 if UndeservingRural==2
	replace DeservingRural=9 if UndeservingRural==1
	replace DeservingRural=10 if UndeservingRural==0

	gen DeservingNonuniv=0 if UndeservingNonuniv==10
	replace DeservingNonuniv=1 if UndeservingNonuniv==9
	replace DeservingNonuniv=2 if UndeservingNonuniv==8
	replace DeservingNonuniv=3 if UndeservingNonuniv==7
	replace DeservingNonuniv=4 if UndeservingNonuniv==6
	replace DeservingNonuniv=5 if UndeservingNonuniv==5
	replace DeservingNonuniv=6 if UndeservingNonuniv==4
	replace DeservingNonuniv=7 if UndeservingNonuniv==3
	replace DeservingNonuniv=8 if UndeservingNonuniv==2
	replace DeservingNonuniv=9 if UndeservingNonuniv==1
	replace DeservingNonuniv=10 if UndeservingNonuniv==0

	gen DeservingWomen=0 if UndeservingWomen==10
	replace DeservingWomen=1 if UndeservingWomen==9
	replace DeservingWomen=2 if UndeservingWomen==8
	replace DeservingWomen=3 if UndeservingWomen==7
	replace DeservingWomen=4 if UndeservingWomen==6
	replace DeservingWomen=5 if UndeservingWomen==5
	replace DeservingWomen=6 if UndeservingWomen==4
	replace DeservingWomen=7 if UndeservingWomen==3
	replace DeservingWomen=8 if UndeservingWomen==2
	replace DeservingWomen=9 if UndeservingWomen==1
	replace DeservingWomen=10 if UndeservingWomen==0

	gen DeservingElderly=0 if UndeservingElderly==10
	replace DeservingElderly=1 if UndeservingElderly==9
	replace DeservingElderly=2 if UndeservingElderly==8
	replace DeservingElderly=3 if UndeservingElderly==7
	replace DeservingElderly=4 if UndeservingElderly==6
	replace DeservingElderly=5 if UndeservingElderly==5
	replace DeservingElderly=6 if UndeservingElderly==4
	replace DeservingElderly=7 if UndeservingElderly==3
	replace DeservingElderly=8 if UndeservingElderly==2
	replace DeservingElderly=9 if UndeservingElderly==1
	replace DeservingElderly=10 if UndeservingElderly==0

	gen DeservingEthnic=0 if UndeservingEthnic==10
	replace DeservingEthnic=1 if UndeservingEthnic==9
	replace DeservingEthnic=2 if UndeservingEthnic==8
	replace DeservingEthnic=3 if UndeservingEthnic==7
	replace DeservingEthnic=4 if UndeservingEthnic==6
	replace DeservingEthnic=5 if UndeservingEthnic==5
	replace DeservingEthnic=6 if UndeservingEthnic==4
	replace DeservingEthnic=7 if UndeservingEthnic==3
	replace DeservingEthnic=8 if UndeservingEthnic==2
	replace DeservingEthnic=9 if UndeservingEthnic==1
	replace DeservingEthnic=10 if UndeservingEthnic==0

	** working class vignette
	eststo work1: reg CandidateWorkingVignette i.WorkingGroup##i.WorkingVignetteTreatment##c.ImportanceClass  LabourVignette2 i.SuccesAttention, cluster(caseid)

	margins, dydx(WorkingVignetteTreatment) at(WorkingGroup=(0) ImportanceClass=(0(1)10))
	mplotoffset, offset(0.0) recast(line) recastci(rarea) xtitle("Importance class identity")  title("") ytitle("AME assignment to treatment") ylabel(-6(2)6) legend( nobox cols(1) ring(0) bplacement(ne) region(col(white))) yline(0, lpattern(dash)) ciopt(color(gs14) alwidth(none)) ci1opt(color(gs5) alwidth(none)) xlabel(0(2)10)xsize(3.5) ysize(2) scale(1.5) saving(workIDstrengthOutgroup.gph, replace)
		
	margins, dydx(WorkingVignetteTreatment) at(WorkingGroup=(1) ImportanceClass=(0(1)10))
	mplotoffset, offset(0.0) recast(line) recastci(rarea) xtitle("Importance class identity")  title("") ytitle("AME assignment to treatment") ylabel(-6(2)6) legend( nobox cols(1) ring(0) bplacement(ne) region(col(white))) yline(0, lpattern(dash)) ciopt(color(gs14) alwidth(none)) ci1opt(color(gs5) alwidth(none)) xlabel(0(2)10)xsize(3.5) ysize(2) scale(1.5) saving(workIDstrengthIngroup.gph, replace)

	eststo work2: reg CandidateWorkingVignette i.WorkingGroup##i.WorkingVignetteTreatment##c.DeservingWorkingclass  LabourVignette2 i.SuccesAttention, cluster(caseid)

	margins, dydx(WorkingVignetteTreatment) at(WorkingGroup=(0) DeservingWorkingclass=(0(1)10))
	mplotoffset, offset(0.0) recast(line) recastci(rarea) xtitle("Deservingness working class")  title("") ytitle("AME assignment to treatment") ylabel(-6(2)6) legend( nobox cols(1) ring(0) bplacement(ne) region(col(white))) yline(0, lpattern(dash)) ciopt(color(gs14) alwidth(none)) ci1opt(color(gs5) alwidth(none)) xlabel(0(2)10) xsize(3.5) ysize(2) scale(1.5) saving(workDeservingOutgroup.gph, replace)

	margins, dydx(WorkingVignetteTreatment) at(WorkingGroup=(1) DeservingWorkingclass=(0(1)10))
	mplotoffset, offset(0.0) recast(line) recastci(rarea) xtitle("Deservingness working class")  title("") ytitle("AME assignment to treatment") ylabel(-6(2)6) legend( nobox cols(1) ring(0) bplacement(ne) region(col(white))) yline(0, lpattern(dash)) ciopt(color(gs14) alwidth(none)) ci1opt(color(gs5) alwidth(none)) xlabel(0(2)10) xsize(3.5) ysize(2) scale(1.5) saving(workDeservingIngroup.gph, replace)

	** rural 	
	eststo rural1: reg CandidateRuralVignette i.RuralGroup##i.RuralVignetteTreatment##c.ImportancePlace  LabourVignette3 i.SuccesAttention, cluster(caseid)

	margins, dydx(RuralVignetteTreatment) at(RuralGroup=(0) ImportancePlace=(0(1)10))
	mplotoffset, offset(0.0) recast(line) recastci(rarea) xtitle("Importance class identity")  title("") ytitle("AME assignment to treatment") ylabel(-6(2)6) legend( nobox cols(1) ring(0) bplacement(ne) region(col(white))) yline(0, lpattern(dash)) ciopt(color(gs14) alwidth(none)) ci1opt(color(gs5) alwidth(none)) xlabel(0(2)10) xsize(3.5) ysize(2) scale(1.5) saving(ruralIDstrengthOutgroup.gph, replace)
	
	margins, dydx(RuralVignetteTreatment) at(RuralGroup=(1) ImportancePlace=(0(1)10))
	mplotoffset, offset(0.0) recast(line) recastci(rarea) xtitle("Importance class identity")  title("") ytitle("AME assignment to treatment") ylabel(-6(2)6) legend( nobox cols(1) ring(0) bplacement(ne) region(col(white))) yline(0, lpattern(dash)) ciopt(color(gs14) alwidth(none)) ci1opt(color(gs5) alwidth(none)) xlabel(0(2)10) xsize(3.5) ysize(2) scale(1.5) saving(ruralIDstrengthIngroup.gph, replace)

	eststo rural2: reg CandidateRuralVignette i.RuralGroup##i.RuralVignetteTreatment##c.DeservingRural LabourVignette3 i.SuccesAttention, cluster(caseid)

	margins, dydx(RuralVignetteTreatment) at(RuralGroup=(0) DeservingRural=(0(1)10))
	mplotoffset, offset(0.0) recast(line) recastci(rarea) xtitle("Deservingness rural people")  title("") ytitle("AME assignment to treatment") ylabel(-6(2)6) legend( nobox cols(1) ring(0) bplacement(ne) region(col(white))) yline(0, lpattern(dash)) ciopt(color(gs14) alwidth(none)) ci1opt(color(gs5) alwidth(none)) xlabel(0(2)10) xsize(3.5) ysize(2) scale(1.5) saving(ruralDeservingOutgroup.gph, replace)

	margins, dydx(RuralVignetteTreatment) at(RuralGroup=(1) DeservingRural=(0(1)10))
	mplotoffset, offset(0.0) recast(line) recastci(rarea) xtitle("Deservingness rural people")  title("") ytitle("AME assignment to treatment") ylabel(-6(2)6) legend( nobox cols(1) ring(0) bplacement(ne) region(col(white))) yline(0, lpattern(dash)) ciopt(color(gs14) alwidth(none)) ci1opt(color(gs5) alwidth(none)) xlabel(0(2)10) xsize(3.5) ysize(2) scale(1.5) saving(ruralDeservingIngroup.gph, replace)
	
	** non university	
	eststo edu1: reg CandidateNonunivVignette i.EducationGroup##i.NonunivVignetteTreatment##c.ImportanceEducation  LabourVignette4 i.SuccesAttention, cluster(caseid)

	margins, dydx(NonunivVignetteTreatment) at(EducationGroup=(0) ImportanceEducation=(0(1)10))
	mplotoffset, offset(0.0) recast(line) recastci(rarea) xtitle("Importance education identity")  title("") ytitle("AME assignment to treatment") ylabel(-6(2)6) legend( nobox cols(1) ring(0) bplacement(ne) region(col(white))) yline(0, lpattern(dash)) ciopt(color(gs14) alwidth(none)) ci1opt(color(gs5) alwidth(none)) xlabel(0(2)10) xsize(3.5) ysize(2) scale(1.5) saving(nonunivIDstrengthOutgroup.gph, replace)
	
	margins, dydx(NonunivVignetteTreatment) at(EducationGroup=(1) ImportanceEducation=(0(1)10))
	mplotoffset, offset(0.0) recast(line) recastci(rarea) xtitle("Importance education identity")  title("") ytitle("AME assignment to treatment") ylabel(-6(2)6) legend( nobox cols(1) ring(0) bplacement(ne) region(col(white))) yline(0, lpattern(dash)) ciopt(color(gs14) alwidth(none)) ci1opt(color(gs5) alwidth(none)) xlabel(0(2)10) xsize(3.5) ysize(2) scale(1.5) saving(nonunivIDstrengthIngroup.gph, replace)

	eststo edu2: reg CandidateNonunivVignette i.EducationGroup##i.NonunivVignetteTreatment##c.DeservingNonuniv LabourVignette4 i.SuccesAttention, cluster(caseid)

	margins, dydx(NonunivVignetteTreatment) at(EducationGroup=(0) DeservingNonuniv=(0(1)10))
	mplotoffset, offset(0.0) recast(line) recastci(rarea) xtitle("Deservingness non-university graduates")  title("") ytitle("AME assignment to treatment") ylabel(-6(2)6) legend( nobox cols(1) ring(0) bplacement(ne) region(col(white))) yline(0, lpattern(dash)) ciopt(color(gs14) alwidth(none)) ci1opt(color(gs5) alwidth(none)) xlabel(0(2)10) xsize(3.5) ysize(2) scale(1.5) saving(nonunivDeservingOutgroup.gph, replace)

	margins, dydx(NonunivVignetteTreatment) at(EducationGroup=(1) DeservingNonuniv=(0(1)10))
	mplotoffset, offset(0.0) recast(line) recastci(rarea) xtitle("Deservingness non-university graduates")  title("") ytitle("AME assignment to treatment") ylabel(-6(2)6) legend( nobox cols(1) ring(0) bplacement(ne) region(col(white))) yline(0, lpattern(dash)) ciopt(color(gs14) alwidth(none)) ci1opt(color(gs5) alwidth(none)) xlabel(0(2)10) xsize(3.5) ysize(2) scale(1.5) saving(nonunivDeservingIngroup.gph, replace)
	
	** women	
	eststo women1: reg CandidateWomenVignette i.WomenGroup##i.WomenVignetteTreatment##c.ImportanceGender  LabourVignette5 i.SuccesAttention, cluster(caseid)

	margins, dydx(WomenVignetteTreatment) at(WomenGroup=(0) ImportanceGender=(0(1)10))
	mplotoffset, offset(0.0) recast(line) recastci(rarea) xtitle("Importance gender identity")  title("") ytitle("AME assignment to treatment") ylabel(-6(2)6) legend( nobox cols(1) ring(0) bplacement(ne) region(col(white))) yline(0, lpattern(dash)) ciopt(color(gs14) alwidth(none)) ci1opt(color(gs5) alwidth(none)) xlabel(0(2)10) xsize(3.5) ysize(2) scale(1.5) saving(womenIDstrengthOutgroup.gph, replace)
	
	margins, dydx(WomenVignetteTreatment) at(WomenGroup=(1) ImportanceGender=(0(1)10))
	mplotoffset, offset(0.0) recast(line) recastci(rarea) xtitle("Importance gender identity")  title("") ytitle("AME assignment to treatment") ylabel(-6(2)6) legend( nobox cols(1) ring(0) bplacement(ne) region(col(white))) yline(0, lpattern(dash)) ciopt(color(gs14) alwidth(none)) ci1opt(color(gs5) alwidth(none)) xlabel(0(2)10) xsize(3.5) ysize(2) scale(1.5) saving(womenIDstrengthIngroup.gph, replace)

	eststo women2: reg CandidateWomenVignette i.WomenGroup##i.WomenVignetteTreatment##c.DeservingWomen LabourVignette5 i.SuccesAttention, cluster(caseid)

	margins, dydx(WomenVignetteTreatment) at(WomenGroup=(0) DeservingWomen=(0(1)10))
	mplotoffset, offset(0.0) recast(line) recastci(rarea) xtitle("Deservingness women")  title("") ytitle("AME assignment to treatment") ylabel(-6(2)6) legend( nobox cols(1) ring(0) bplacement(ne) region(col(white))) yline(0, lpattern(dash)) ciopt(color(gs14) alwidth(none)) ci1opt(color(gs5) alwidth(none)) xlabel(0(2)10) xsize(3.5) ysize(2) scale(1.5) saving(womenDeservingOutgroup.gph, replace)

	margins, dydx(WomenVignetteTreatment) at(WomenGroup=(1) DeservingWomen=(0(1)10))
	mplotoffset, offset(0.0) recast(line) recastci(rarea) xtitle("Deservingness women")  title("") ytitle("AME assignment to treatment") ylabel(-6(2)6) legend( nobox cols(1) ring(0) bplacement(ne) region(col(white))) yline(0, lpattern(dash)) ciopt(color(gs14) alwidth(none)) ci1opt(color(gs5) alwidth(none)) xlabel(0(2)10) xsize(3.5) ysize(2) scale(1.5) saving(womenDeservingIngroup.gph, replace)
	
	** elderly
	eststo elderly1: reg CandidateElderlyVignette i.OldGroup##i.ElderlyVignetteTreatment##c.ImportanceAge  LabourVignette6 i.SuccesAttention, cluster(caseid)

	margins, dydx(ElderlyVignetteTreatment) at(OldGroup=(0) ImportanceAge=(0(1)10))
	mplotoffset, offset(0.0) recast(line) recastci(rarea) xtitle("Importance age identity")  title("") ytitle("AME assignment to treatment") ylabel(-6(2)6) legend( nobox cols(1) ring(0) bplacement(ne) region(col(white))) yline(0, lpattern(dash)) ciopt(color(gs14) alwidth(none)) ci1opt(color(gs5) alwidth(none)) xlabel(0(2)10) xsize(3.5) ysize(2) scale(1.5) saving(oldIDstrengthOutgroup.gph, replace)
	
	margins, dydx(ElderlyVignetteTreatment) at(OldGroup=(1) ImportanceAge=(0(1)10))
	mplotoffset, offset(0.0) recast(line) recastci(rarea) xtitle("Importance age identity")  title("") ytitle("AME assignment to treatment") ylabel(-6(2)6) legend( nobox cols(1) ring(0) bplacement(ne) region(col(white))) yline(0, lpattern(dash)) ciopt(color(gs14) alwidth(none)) ci1opt(color(gs5) alwidth(none)) xlabel(0(2)10) xsize(3.5) ysize(2) scale(1.5) saving(oldIDstrengthIngroup.gph, replace)

	eststo elderly2: reg CandidateElderlyVignette i.OldGroup##i.ElderlyVignetteTreatment##c.DeservingElderly LabourVignette6 i.SuccesAttention, cluster(caseid)

	margins, dydx(ElderlyVignetteTreatment) at(OldGroup=(0) DeservingElderly=(0(1)10))
	mplotoffset, offset(0.0) recast(line) recastci(rarea) xtitle("Deservingness elderly")  title("") ytitle("AME assignment to treatment") ylabel(-6(2)6) legend( nobox cols(1) ring(0) bplacement(ne) region(col(white))) yline(0, lpattern(dash)) ciopt(color(gs14) alwidth(none)) ci1opt(color(gs5) alwidth(none)) xlabel(0(2)10) xsize(3.5) ysize(2) scale(1.5) saving(oldDeservingOutgroup.gph, replace)

	margins, dydx(ElderlyVignetteTreatment) at(OldGroup=(1) DeservingElderly=(0(1)10))
	mplotoffset, offset(0.0) recast(line) recastci(rarea) xtitle("Deservingness elderly")  title("") ytitle("AME assignment to treatment") ylabel(-6(2)6) legend( nobox cols(1) ring(0) bplacement(ne) region(col(white))) yline(0, lpattern(dash)) ciopt(color(gs14) alwidth(none)) ci1opt(color(gs5) alwidth(none)) xlabel(0(2)10) xsize(3.5) ysize(2) scale(1.5) saving(oldDeservingIngroup.gph, replace)

	** ethnic minorities	
	reg CandidateEthnicVignette i.EthnicGroup##i.EthnicVignetteTreatment##c.ImportanceEthnicity  LabourVignette7 i.SuccesAttention, cluster(caseid)

	eststo ethnic1: margins, dydx(EthnicVignetteTreatment) at(EthnicGroup=(0) ImportanceEthnicity=(0(1)10))
	mplotoffset, offset(0.0) recast(line) recastci(rarea) xtitle("Importance ethnic identity")  title("") ytitle("AME assignment to treatment") ylabel(-6(2)6) legend( nobox cols(1) ring(0) bplacement(ne) region(col(white))) yline(0, lpattern(dash)) ciopt(color(gs14) alwidth(none)) ci1opt(color(gs5) alwidth(none)) xlabel(0(2)10) xsize(3.5) ysize(2) scale(1.5) saving(ethnicIDstrengthOutgroup.gph, replace)
	
	margins, dydx(EthnicVignetteTreatment) at(EthnicGroup=(1) ImportanceEthnicity=(0(1)10))
	mplotoffset, offset(0.0) recast(line) recastci(rarea) xtitle("Importance ethnic identity")  title("") ytitle("AME assignment to treatment") ylabel(-6(2)6) legend( nobox cols(1) ring(0) bplacement(ne) region(col(white))) yline(0, lpattern(dash)) ciopt(color(gs14) alwidth(none)) ci1opt(color(gs5) alwidth(none)) xlabel(0(2)10) xsize(3.5) ysize(2) scale(1.5) saving(ethnicIDstrengthIngroup.gph, replace)

	eststo ethnic2: reg CandidateEthnicVignette i.EthnicGroup##i.EthnicVignetteTreatment##c.DeservingEthnic LabourVignette7 i.SuccesAttention, cluster(caseid)

	margins, dydx(EthnicVignetteTreatment) at(EthnicGroup=(0) DeservingEthnic=(0(1)10))
	mplotoffset, offset(0.0) recast(line) recastci(rarea) xtitle("Deservingness ethnic minorities")  title("") ytitle("AME assignment to treatment") ylabel(-6(2)6) legend( nobox cols(1) ring(0) bplacement(ne) region(col(white))) yline(0, lpattern(dash)) ciopt(color(gs14) alwidth(none)) ci1opt(color(gs5) alwidth(none)) xlabel(0(2)10) xsize(3.5) ysize(2) scale(1.5) saving(ethnicDeservingOutgroup.gph, replace)

	margins, dydx(EthnicVignetteTreatment) at(EthnicGroup=(1) DeservingEthnic=(0(1)10))
	mplotoffset, offset(0.0) recast(line) recastci(rarea) xtitle("Deservingness ethnic minorities")  title("") ytitle("AME assignment to treatment") ylabel(-6(2)6) legend( nobox cols(1) ring(0) bplacement(ne) region(col(white))) yline(0, lpattern(dash)) ciopt(color(gs14) alwidth(none)) ci1opt(color(gs5) alwidth(none)) xlabel(0(2)10) xsize(3.5) ysize(2) scale(1.5) saving(ethnicDeservingIngroup.gph, replace)

	** tables appendix N
	esttab work1 rural1 edu1  using appendixNtable1.tex, b(3) se(3) r2 nogap  replace
	esttab  women1 elderly1 ethnic1 using appendixNtable2.tex, b(3) se(3) r2 nogap  replace

	** tables appendix O
	esttab work2 rural2 edu2 using appendixOtable1.tex, b(3) se(3) r2 nogap  replace	
	esttab  women2 elderly2 ethnic2 using appendixOtable2.tex, b(3) se(3) r2 nogap  replace		
	
	
* -------------------------------------	
* appendix P, shared party (study 2)	
* -------------------------------------	

	** set working directory first
	cd "~/dropbox/symbolic group appeals project/replication materials/data"
	
	** load data
	use "study2-coded.dta", clear
	
	** set working directory for saving graphs and tables
	cd "~/dropbox/symbolic group appeals project/replication materials/tables and figures"
	
	** stack data and prepare data
	gen Candidate1=CandidateControl 
	gen Candidate2=CandidateWorking 
	gen Candidate3=CandidateRural 
	gen Candidate4=CandidateNonuniv 
	gen Candidate5=CandidateWomen 
	gen Candidate6=CandidateElderly 
	gen Candidate7=CandidateEthnic 
	gen Candidate8=CandidateBroad

	gen CandidateAll2=Candidate2						// candidate evaluations for control group are repeated
	replace CandidateAll2=Candidate1 if Candidate2==.	

	gen CandidateAll3=Candidate3						// candidate evaluations for control group are repeated
	replace CandidateAll3=Candidate1 if Candidate3==.	

	gen CandidateAll4=Candidate4						// candidate evaluations for control group are repeated
	replace CandidateAll4=Candidate1 if Candidate4==.	

	gen CandidateAll5=Candidate5						// candidate evaluations for control group are repeated
	replace CandidateAll5=Candidate1 if Candidate5==.	

	gen CandidateAll6=Candidate6						// candidate evaluations for control group are repeated
	replace CandidateAll6=Candidate1 if Candidate6==.	

	gen CandidateAll7=Candidate7						// candidate evaluations for control group are repeated
	replace CandidateAll7=Candidate1 if Candidate7==.	

	gen CandidateAll8=Candidate8						// candidate evaluations for control group are repeated
	replace CandidateAll8=Candidate1 if Candidate8==.	

	gen Vignette1=1 if arm_treatment==1
	replace Vignette1=0 if arm_treatment==2
	gen Vignette2=WorkingVignetteTreatment 
	gen Vignette3=RuralVignetteTreatment 
	gen Vignette4=NonunivVignetteTreatment 
	gen Vignette5=WomenVignetteTreatment 
	gen Vignette6=ElderlyVignetteTreatment 
	gen Vignette7=EthnicVignetteTreatment 
	gen Vignette8=BroadVignetteTreatment

	gen Ingroup2=WorkingGroup
	gen Ingroup3=RuralGroup
	gen Ingroup4=EducationGroup
	gen Ingroup5=WomenGroup
	gen Ingroup6=OldGroup
	gen Ingroup7=EthnicGroup

	gen Importance2=ImportanceClass
	gen Importance3=ImportancePlace
	gen Importance4=ImportanceEducation
	gen Importance5=ImportanceGender
	gen Importance6=ImportanceAge
	gen Importance7=ImportanceEthnicity

	gen Undeserving2=UndeservingWorkingClass
	gen Undeserving3=UndeservingRural
	gen Undeserving4=UndeservingNonuniv
	gen Undeserving5=UndeservingWomen
	gen Undeserving6=UndeservingElderly
	gen Undeserving7=UndeservingEthnic

	gen LikeGroup2=LikeWorkingClass
	gen LikeGroup3=LikeRural
	gen LikeGroup4=LikeNonuniv
	gen LikeGroup5=LikeWomen
	gen LikeGroup6=LikeElderly
	gen LikeGroup7=LikeEthnic

	reshape long Candidate CandidateAll Vignette Ingroup Importance Undeserving LikeGroup OrderVignette LabourVignette, i(caseid) j(number)  

	gen appeal=1 if arm_treatment==2		// assigned to an appeal
	replace appeal=0 if arm_treatment==1	// assigned to control

	gen SharedPartisan=0			
	replace SharedPartisan=1 if LabourVignette==1 & profile_partyid==2	// labour partisans
	replace SharedPartisan=1 if LabourVignette==0 & profile_partyid==1	// conservative partisans 

	gen PID3groups=0 if profile_partyid==6								// non-partisan 
	replace PID3groups=1 if SharedPartisan==1							// partisan candidate's party
	replace PID3groups=2 if SharedPartisan!=1 & profile_partyid<=5		// partisan other party

	gen Deserving=0 if Undeserving==10
	replace Deserving=1 if Undeserving==9
	replace Deserving=2 if Undeserving==8
	replace Deserving=3 if Undeserving==7
	replace Deserving=4 if Undeserving==6
	replace Deserving=5 if Undeserving==5
	replace Deserving=6 if Undeserving==4
	replace Deserving=7 if Undeserving==3
	replace Deserving=8 if Undeserving==2
	replace Deserving=9 if Undeserving==1
	replace Deserving=10 if Undeserving==0

	** interaction identity strength
	eststo shared1: reg CandidateAll i.Ingroup##appeal##c.Importance SharedPartisan SuccesAttention, cluster(caseid)
	
	margins, dydx(appeal) at(Ingroup=(0) Importance=(0(1)10))
	mplotoffset, offset(0.0) recast(line) recastci(rarea) xtitle("Identity strength")  title("") ytitle("AME assignment to group appeal") ylabel(-2(1)2) legend( nobox cols(1) ring(0) bplacement(ne) region(col(white))) yline(0, lpattern(dash)) ciopt(color(gs14) alwidth(none)) ci1opt(color(gs5) alwidth(none)) xlabel(0(2)10)  xsize(3.5) ysize(2) scale(1.5) title("") saving(PooledImportanceOutgroupPID.gph, replace)
	
	margins, dydx(appeal) at(Ingroup=(1) Importance=(0(1)10))
	mplotoffset, offset(0.0) recast(line) recastci(rarea) xtitle("Identity strength")  title("") ytitle("AME assignment to group appeal") ylabel(-2(1)2) legend( nobox cols(1) ring(0) bplacement(ne) region(col(white))) yline(0, lpattern(dash)) ciopt(color(gs14) alwidth(none)) ci1opt(color(gs5) alwidth(none)) xlabel(0(2)10)  xsize(3.5) ysize(2) scale(1.5) title("") saving(PooledImportanceIngroupPID.gph, replace)
		
	** interaction deservingness
	eststo shared2: reg CandidateAll i.Ingroup##appeal##c.Deserving SharedPartisan SuccesAttention, cluster(caseid)
	
	margins, dydx(appeal) at(Ingroup=(0) Deserving=(0(1)10))
	mplotoffset, offset(0.0) recast(line) recastci(rarea) xtitle("Group is deserving")  title("") ytitle("AME assignment to group appeal") ylabel(-3(1)3) legend( nobox cols(1) ring(0) bplacement(ne) region(col(white))) yline(0, lpattern(dash)) ciopt(color(gs14) alwidth(none)) ci1opt(color(gs5) alwidth(none)) xlabel(0(2)10)  xsize(3.5) ysize(2) scale(1.5) title("") saving(PooledDeservingOutgroupPID.gph, replace)
	
	margins, dydx(appeal) at(Ingroup=(1) Deserving=(0(1)10))
	mplotoffset, offset(0.0) recast(line) recastci(rarea) xtitle("Group is deserving")  title("") ytitle("AME assignment to group appeal") ylabel(-3(1)3) legend( nobox cols(1) ring(0) bplacement(ne) region(col(white))) yline(0, lpattern(dash)) ciopt(color(gs14) alwidth(none)) ci1opt(color(gs5) alwidth(none)) xlabel(0(2)10)  xsize(3.5) ysize(2) scale(1.5) title("")  saving(PooledDeservingIngroupPID.gph, replace)	

	** table with underlying estimates
	esttab shared1 shared2 using appendixPtable2.tex, b(3) se(3) r2 nogap  replace	


* -----------------------------
* appendix Q, group affect	
* -----------------------------	
	
	* only like/dislike
	eststo affect1: reg CandidateAll i.Ingroup##appeal##c.LikeGroup LabourVignette SuccesAttention, cluster(caseid)
	
	margins, dydx(appeal) at(Ingroup=(0) LikeGroup=(0(1)10))
	mplotoffset, offset(0.0) recast(line) recastci(rarea) xtitle("Like/dislike group")  title("") ytitle("AME assignment to group appeal") ylabel(-3(1)3) legend( nobox cols(1) ring(0) bplacement(ne) region(col(white))) yline(0, lpattern(dash)) ciopt(color(gs14) alwidth(none)) ci1opt(color(gs5) alwidth(none)) xlabel(0(2)10) xsize(3.5) ysize(2) scale(1.5) title("") saving(PooledLikeDislikeOutgroup.gph, replace)
	
	margins, dydx(appeal) at(Ingroup=(1) LikeGroup=(0(1)10))
	mplotoffset, offset(0.0) recast(line) recastci(rarea) xtitle("Like/dislike group")  title("") ytitle("AME assignment to group appeal") ylabel(-3(1)3) legend( nobox cols(1) ring(0) bplacement(ne) region(col(white))) yline(0, lpattern(dash)) ciopt(color(gs14) alwidth(none)) ci1opt(color(gs5) alwidth(none)) xlabel(0(2)10) xsize(3.5) ysize(2) scale(1.5) title("")  saving(PooledLikeDislikeIngroup.gph, replace)	
	
	* social identity strength and controlling for like/dislike
	eststo affect2: reg CandidateAll i.Ingroup##i.appeal##c.Importance i.Ingroup##i.appeal##c.LikeGroup i.SuccesAttention LabourVignette, cluster(caseid)

	margins, dydx(appeal) at(Ingroup=(0) Importance=(0(1)10))
	mplotoffset, offset(0.0) recast(line) recastci(rarea) xtitle("Identity strength")  title("") ytitle("AME assignment to group appeal") ylabel(-2(1)2) legend( nobox cols(1) ring(0) bplacement(ne) region(col(white))) yline(0, lpattern(dash)) ciopt(color(gs14) alwidth(none)) ci1opt(color(gs5) alwidth(none)) xlabel(0(2)10) xsize(3.5) ysize(2) scale(1.5) title("") saving(PooledImportanceLikeOutgroup.gph, replace)
	
	margins, dydx(appeal) at(Ingroup=(1) Importance=(0(1)10))
	mplotoffset, offset(0.0) recast(line) recastci(rarea) xtitle("Identity strength")  title("") ytitle("AME assignment to group appeal") ylabel(-2(1)2) legend( nobox cols(1) ring(0) bplacement(ne) region(col(white))) yline(0, lpattern(dash)) ciopt(color(gs14) alwidth(none)) ci1opt(color(gs5) alwidth(none)) xlabel(0(2)10) xsize(3.5) ysize(2) scale(1.5) title("") saving(PooledImportanceLikeIngroup.gph, replace)
	
	* deservingness and controlling for like/dislike
	eststo affect3: reg CandidateAll i.Ingroup##i.appeal##c.Deserving i.Ingroup##i.appeal##c.LikeGroup i.SuccesAttention LabourVignette, cluster(caseid)

	margins, dydx(appeal) at(Ingroup=(0) Deserving=(0(1)10))
	mplotoffset, offset(0.0) recast(line) recastci(rarea) xtitle("Group is deserving")  title("") ytitle("AME assignment to group appeal") ylabel(-3(1)3) legend( nobox cols(1) ring(0) bplacement(ne) region(col(white))) yline(0, lpattern(dash)) ciopt(color(gs14) alwidth(none)) ci1opt(color(gs5) alwidth(none)) xlabel(0(2)10) xsize(3.5) ysize(2) scale(1.5) title("") saving(PooledDeservingLikeOutgroup.gph, replace)
	
	margins, dydx(appeal) at(Ingroup=(1) Deserving=(0(1)10))
	mplotoffset, offset(0.0) recast(line) recastci(rarea) xtitle("Group is deserving")  title("") ytitle("AME assignment to group appeal") ylabel(-3(1)3) legend( nobox cols(1) ring(0) bplacement(ne) region(col(white))) yline(0, lpattern(dash)) ciopt(color(gs14) alwidth(none)) ci1opt(color(gs5) alwidth(none)) xlabel(0(2)10) xsize(3.5) ysize(2) scale(1.5) title("")  saving(PooledDeservingLikeIngroup.gph, replace)	
	
	** table with underlying estimates
	esttab affect1 affect2 affect3 using appendixQtable.tex, b(3) se(3) r2 nogap  replace		
	
	
	
* ----------------------------------
* appendix R, party heterogeneity
* ----------------------------------

	** interaction identity strength
	eststo party1: reg CandidateAll i.Ingroup##appeal##c.Importance##i.LabourVignette SuccesAttention, cluster(caseid)
	
	margins, dydx(appeal) at(Ingroup=(0) Importance=(0(1)10) LabourVignette=(1))
	mplotoffset, offset(0.0) recast(line) recastci(rarea) xtitle("Identity strength")  title("") ytitle("AME assignment to group appeal") ylabel(-2(1)3) legend( nobox cols(1) ring(0) bplacement(ne) region(col(white))) yline(0, lpattern(dash)) ciopt(color(gs14) alwidth(none)) ci1opt(color(gs5) alwidth(none)) xlabel(0(2)10) xsize(3.5) ysize(2) scale(1.5) title("") saving(PooledImportanceOutgroupLabour.gph, replace)
	
	margins, dydx(appeal) at(Ingroup=(1) Importance=(0(1)10) LabourVignette=(1))
	mplotoffset, offset(0.0) recast(line) recastci(rarea) xtitle("Identity strength")  title("") ytitle("AME assignment to group appeal") ylabel(-2(1)3) legend( nobox cols(1) ring(0) bplacement(ne) region(col(white))) yline(0, lpattern(dash)) ciopt(color(gs14) alwidth(none)) ci1opt(color(gs5) alwidth(none)) xlabel(0(2)10) xsize(3.5) ysize(2) scale(1.5) title("") saving(PooledImportanceIngroupLabour.gph, replace)

	margins, dydx(appeal) at(Ingroup=(0) Importance=(0(1)10) LabourVignette=(0))
	mplotoffset, offset(0.0) recast(line) recastci(rarea) xtitle("Identity strength")  title("") ytitle("AME assignment to group appeal") ylabel(-2(1)3) legend( nobox cols(1) ring(0) bplacement(ne) region(col(white))) yline(0, lpattern(dash)) ciopt(color(gs14) alwidth(none)) ci1opt(color(gs5) alwidth(none)) xlabel(0(2)10) xsize(3.5) ysize(2) scale(1.5) title("") saving(PooledImportanceOutgroupCons.gph, replace)
	
	margins, dydx(appeal) at(Ingroup=(1) Importance=(0(1)10) LabourVignette=(0))
	mplotoffset, offset(0.0) recast(line) recastci(rarea) xtitle("Identity strength")  title("") ytitle("AME assignment to group appeal") ylabel(-2(1)3) legend( nobox cols(1) ring(0) bplacement(ne) region(col(white))) yline(0, lpattern(dash)) ciopt(color(gs14) alwidth(none)) ci1opt(color(gs5) alwidth(none)) xlabel(0(2)10) xsize(3.5) ysize(2) scale(1.5) title("") saving(PooledImportanceIngroupCons.gph, replace)

	** interaction deservingness
	eststo party2: reg CandidateAll i.Ingroup##appeal##c.Deserving##i.LabourVignette SuccesAttention, cluster(caseid)
	
	margins, dydx(appeal) at(Ingroup=(0) Deserving=(0(1)10) LabourVignette=(1))
	mplotoffset, offset(0.0) recast(line) recastci(rarea) xtitle("Group is deserving")  title("") ytitle("AME assignment to group appeal") ylabel(-3(1)3) legend( nobox cols(1) ring(0) bplacement(ne) region(col(white))) yline(0, lpattern(dash)) ciopt(color(gs14) alwidth(none)) ci1opt(color(gs5) alwidth(none)) xlabel(0(2)10) xsize(3.5) ysize(2) scale(1.5) title("") saving(PooledDeservingOutgroupLabour.gph, replace)
	
	margins, dydx(appeal) at(Ingroup=(1) Deserving=(0(1)10) LabourVignette=(1))
	mplotoffset, offset(0.0) recast(line) recastci(rarea) xtitle("Group is deserving")  title("") ytitle("AME assignment to group appeal") ylabel(-3(1)3) legend( nobox cols(1) ring(0) bplacement(ne) region(col(white))) yline(0, lpattern(dash)) ciopt(color(gs14) alwidth(none)) ci1opt(color(gs5) alwidth(none)) xlabel(0(2)10) xsize(3.5) ysize(2) scale(1.5) title("")  saving(PooledDeservingIngroupLabour.gph, replace)	
	
	margins, dydx(appeal) at(Ingroup=(0) Deserving=(0(1)10) LabourVignette=(0))
	mplotoffset, offset(0.0) recast(line) recastci(rarea) xtitle("Group is deserving")  title("") ytitle("AME assignment to group appeal") ylabel(-3(1)4) legend( nobox cols(1) ring(0) bplacement(ne) region(col(white))) yline(0, lpattern(dash)) ciopt(color(gs14) alwidth(none)) ci1opt(color(gs5) alwidth(none)) xlabel(0(2)10) xsize(3.5) ysize(2) scale(1.5) title("") saving(PooledDeservingOutgroupCons.gph, replace)
	
	margins, dydx(appeal) at(Ingroup=(1) Deserving=(0(1)10) LabourVignette=(0))
	mplotoffset, offset(0.0) recast(line) recastci(rarea) xtitle("Group is deserving")  title("") ytitle("AME assignment to group appeal") ylabel(-3(1)4) legend( nobox cols(1) ring(0) bplacement(ne) region(col(white))) yline(0, lpattern(dash)) ciopt(color(gs14) alwidth(none)) ci1opt(color(gs5) alwidth(none)) xlabel(0(2)10) xsize(3.5) ysize(2) scale(1.5) title("")  saving(PooledDeservingIngroupCons.gph, replace)		
	
	** table with underlying estimates
	esttab party1 party2 using appendixRtable.tex, b(3) se(3) r2 nogap  replace	


* ----------------------------------
* appendix S, vignette order
* ----------------------------------

	/* note that control group is dropped for these analyses, as Respondents only saw 1 vignette */
	
	preserve
	drop if  OrderVignette==-1
	
	eststo order1: reg CandidateAll i.Ingroup##i.OrderVignette i.SuccesAttention LabourVignette, cluster(caseid)

	margins if OrderVignette!=-1, dydx(Ingroup) at(OrderVignette=(1(1)7))
	mplotoffset, offset(0.15) recast(scatter) recastci(rspike) xtitle("Order in which vignette is shown")  title("") ytitle("AME in-group membership") ylabel(-1(0.5)2) legend( nobox cols(2) pos(6) region(col(white))) xsize(3.5) ysize(2) scale(1.5)  yline(0, lpattern(dash)) saving(vignetteOrder.gph, replace)
	
	esttab order1 using appendixStable.tex, b(3) se(3) r2 nogap  replace	
	restore
	
	
* ----------------------------------
* appendix T, broad appeal
* ----------------------------------	

	** set working directory first
	cd "~/dropbox/symbolic group appeals project/replication materials/data"
	
	** load data
	use "study2-coded.dta", clear
	
	** set working directory for saving graphs and tables
	cd "~/dropbox/symbolic group appeals project/replication materials/tables and figures"

	
	** class
	eststo class1: reg CandidateWorkingVignette i.WorkingGroup##i.WorkingVignetteTreatment  i.LabourVignette2 i.SuccesAttention

	margins, dydx(WorkingVignetteTreatment ) at(WorkingGroup=(0 1))
	mplotoffset, offset(0.15) recast(scatter) recastci(rspike) xtitle("") xlabel(0 "Not working class" 1 "Working class") title("") ytitle("AME assignment to working class appeal") ylabel(-1(1)3) legend( nobox cols(2) pos(6) region(col(white))) xsize(3.5) ysize(2) scale(1.5)  yline(0, lpattern(dash)) saving(workControl-small.gph, replace)

	eststo class2: reg CandidateBroadVignette i.WorkingGroup##i.BroadVignetteTreatment i.LabourVignette8 i.SuccesAttention	

	margins, dydx(BroadVignetteTreatment ) at(WorkingGroup=(0 1))
	mplotoffset, offset(0.15) recast(scatter) recastci(rspike) xtitle("") xlabel(0 "Not working class" 1 "Working class") title("") ytitle("AME assignment to broad appeal") ylabel(-1(1)3) legend( nobox cols(2) pos(6) region(col(white))) xsize(3.5) ysize(2) scale(1.5)  yline(0, lpattern(dash)) saving(workControlBroad.gph, replace)

	** rural
	eststo rural1: reg CandidateRuralVignette i.RuralGroup##i.RuralVignetteTreatment i.LabourVignette3 i.SuccesAttention

	margins, dydx(RuralVignetteTreatment) at(RuralGroup=(0 1))
	mplotoffset, offset(0.15) recast(scatter) recastci(rspike) xtitle("") xlabel(0 "Not in rural area" 1 "Rural area") title("") ytitle("AME assignment to rural appeal") ylabel(-1(1)3) legend( nobox cols(2) pos(6) region(col(white))) xsize(3.5) ysize(2) scale(1.5) yline(0, lpattern(dash)) saving(ruralControl-small.gph, replace)  

	eststo rural2: reg CandidateBroadVignette i.RuralGroup##i.BroadVignetteTreatment i.LabourVignette8 i.SuccesAttention	

	margins, dydx(BroadVignetteTreatment ) at(RuralGroup=(0 1))
	mplotoffset, offset(0.15) recast(scatter) recastci(rspike) xtitle("") xlabel(0 "Not in rural area" 1 "Rural area") title("") ytitle("AME assignment to broad appeal") ylabel(-1(1)3) legend( nobox cols(2) pos(6) region(col(white))) xsize(3.5) ysize(2) scale(1.5)  yline(0, lpattern(dash)) saving(ruralControlBroad.gph, replace)	

	** university
	eststo uni1: reg CandidateNonunivVignette i.EducationGroup##i.NonunivVignetteTreatment i.LabourVignette4 i.SuccesAttention

	margins, dydx(NonunivVignetteTreatment) at(EducationGroup=(0 1))
	mplotoffset, offset(0.15) recast(scatter) recastci(rspike) xtitle("") xlabel(0 "University degree" 1 "Non University degree") title("") ytitle("AME assignment to non university appeal") ylabel(-1(1)3) legend( nobox cols(2) pos(6) region(col(white))) xsize(3.5) ysize(2) scale(1.5)  yline(0, lpattern(dash)) saving(nonunivControl-small.gph, replace) 

	eststo uni2: reg CandidateBroadVignette i.EducationGroup##i.BroadVignetteTreatment i.LabourVignette8 i.SuccesAttention	

	margins, dydx(BroadVignetteTreatment ) at(EducationGroup=(0 1))
	mplotoffset, offset(0.15) recast(scatter) recastci(rspike) xtitle("") xlabel(0 "University degree" 1 "Non University degree") title("") ytitle("AME assignment to broad appeal") ylabel(-1(1)3) legend( nobox cols(2) pos(6) region(col(white))) xsize(3.5) ysize(2) scale(1.5)  yline(0, lpattern(dash)) saving(nonunivControlBroad.gph, replace)	
	
	** women
	eststo women1: reg CandidateWomenVignette i.WomenGroup##i.WomenVignetteTreatment i.LabourVignette5 i.SuccesAttention

	margins, dydx(WomenVignetteTreatment) at(WomenGroup=(0 1))
	mplotoffset, offset(0.15) recast(scatter) recastci(rspike) xtitle("") xlabel(0 "Not a woman" 1 "Woman") title("") ytitle("AME assignment to women appeal") ylabel(-1(1)3) legend( nobox cols(2) pos(6) region(col(white))) xsize(3.5) ysize(2) scale(1.5)  yline(0, lpattern(dash)) saving(womenControl-small.gph, replace)
	
	eststo women2: reg CandidateBroadVignette i.WomenGroup##i.BroadVignetteTreatment i.LabourVignette8 i.SuccesAttention	

	margins, dydx(BroadVignetteTreatment ) at(WomenGroup=(0 1))
	mplotoffset, offset(0.15) recast(scatter) recastci(rspike) xtitle("") xlabel(0 "Not a woman" 1 "Woman") title("") ytitle("AME assignment to broad appeal") ylabel(-1(1)3) legend( nobox cols(2) pos(6) region(col(white))) xsize(3.5) ysize(2) scale(1.5)  yline(0, lpattern(dash)) saving(womenControlBroad.gph, replace)	
	
	** elderly
	eststo elderly1: reg CandidateElderlyVignette i.OldGroup##i.ElderlyVignetteTreatment i.LabourVignette6 i.SuccesAttention

	margins, dydx(ElderlyVignetteTreatment) at(OldGroup=(0 1))
	mplotoffset, offset(0.15) recast(scatter) recastci(rspike) xtitle("") xlabel(0 "64 years or younger" 1 "65+ years") title("") ytitle("AME assignment to elderly appeal") ylabel(-1(1)3) legend( nobox cols(2) pos(6) region(col(white))) xsize(3.5) ysize(2) scale(1.5)  yline(0, lpattern(dash)) saving(elderlyControl-small.gph, replace)
	
	eststo elderly2: reg CandidateBroadVignette i.OldGroup##i.BroadVignetteTreatment i.LabourVignette8 i.SuccesAttention	

	margins, dydx(BroadVignetteTreatment ) at(OldGroup=(0 1))
	mplotoffset, offset(0.15) recast(scatter) recastci(rspike) xtitle("") xlabel(0 "64 years or younger" 1 "65+ years") title("") ytitle("AME assignment to broad appeal") ylabel(-1(1)3) legend( nobox cols(2) pos(6) region(col(white))) xsize(3.5) ysize(2) scale(1.5)  yline(0, lpattern(dash)) saving(elderlyControlBroad.gph, replace)		

	** ethnic minorities
	eststo ethnic1: reg CandidateEthnicVignette i.EthnicGroup##i.EthnicVignetteTreatment i.LabourVignette7 i.SuccesAttention

	margins, dydx(EthnicVignetteTreatment) at(EthnicGroup=(0 1))
	mplotoffset, offset(0.15) recast(scatter) recastci(rspike) xtitle("") xlabel(0 "No ethnic minority" 1 "Ethnic minority") title("") ytitle("AME assignment to ethnic appeal") ylabel(-1(1)3) legend( nobox cols(2) pos(6) region(col(white))) xsize(3.5) ysize(2) scale(1.5)  yline(0, lpattern(dash)) saving(ethnicControl-small.gph, replace)
	
	eststo ethnic2: reg CandidateBroadVignette i.EthnicGroup##i.BroadVignetteTreatment i.LabourVignette8 i.SuccesAttention	

	margins, dydx(BroadVignetteTreatment ) at(EthnicGroup=(0 1))
	mplotoffset, offset(0.15) recast(scatter) recastci(rspike) xtitle("") xlabel(0 "No ethnic minority" 1 "Ethnic minority") title("") ytitle("AME assignment to broad appeal") ylabel(-1(1)3) legend( nobox cols(2) pos(6) region(col(white))) xsize(3.5) ysize(2) scale(1.5)  yline(0, lpattern(dash)) saving(ethnicControlBroad.gph, replace)		

	** tables with underlying estimates
	esttab class1 class2 using appendixTtable1.tex, b(3) se(3) r2 nogap  replace	
	esttab rural1 rural2 using appendixTtable2.tex, b(3) se(3) r2 nogap  replace	
	esttab uni1 uni2 using appendixTtable3.tex, b(3) se(3) r2 nogap  replace	
	esttab women1 women2 using appendixTtable4.tex, b(3) se(3) r2 nogap  replace	
	esttab elderly1 elderly2 using appendixTtable5.tex, b(3) se(3) r2 nogap  replace	
	esttab ethnic1 ethnic2 using appendixTtable6.tex, b(3) se(3) r2 nogap  replace	


* ----------------------------------
* appendix U, in-group vs. in-party
* ----------------------------------	
	
	** stack data and prepare data
	gen Candidate1=CandidateControl 
	gen Candidate2=CandidateWorking 
	gen Candidate3=CandidateRural 
	gen Candidate4=CandidateNonuniv 
	gen Candidate5=CandidateWomen 
	gen Candidate6=CandidateElderly 
	gen Candidate7=CandidateEthnic 
	gen Candidate8=CandidateBroad

	gen CandidateAll2=Candidate2						// candidate evaluations for control group are repeated
	replace CandidateAll2=Candidate1 if Candidate2==.	

	gen CandidateAll3=Candidate3						// candidate evaluations for control group are repeated
	replace CandidateAll3=Candidate1 if Candidate3==.	

	gen CandidateAll4=Candidate4						// candidate evaluations for control group are repeated
	replace CandidateAll4=Candidate1 if Candidate4==.	

	gen CandidateAll5=Candidate5						// candidate evaluations for control group are repeated
	replace CandidateAll5=Candidate1 if Candidate5==.	

	gen CandidateAll6=Candidate6						// candidate evaluations for control group are repeated
	replace CandidateAll6=Candidate1 if Candidate6==.	

	gen CandidateAll7=Candidate7						// candidate evaluations for control group are repeated
	replace CandidateAll7=Candidate1 if Candidate7==.	

	gen CandidateAll8=Candidate8						// candidate evaluations for control group are repeated
	replace CandidateAll8=Candidate1 if Candidate8==.	

	gen Vignette1=1 if arm_treatment==1
	replace Vignette1=0 if arm_treatment==2
	gen Vignette2=WorkingVignetteTreatment 
	gen Vignette3=RuralVignetteTreatment 
	gen Vignette4=NonunivVignetteTreatment 
	gen Vignette5=WomenVignetteTreatment 
	gen Vignette6=ElderlyVignetteTreatment 
	gen Vignette7=EthnicVignetteTreatment 
	gen Vignette8=BroadVignetteTreatment

	gen Ingroup2=WorkingGroup
	gen Ingroup3=RuralGroup
	gen Ingroup4=EducationGroup
	gen Ingroup5=WomenGroup
	gen Ingroup6=OldGroup
	gen Ingroup7=EthnicGroup

	gen Importance2=ImportanceClass
	gen Importance3=ImportancePlace
	gen Importance4=ImportanceEducation
	gen Importance5=ImportanceGender
	gen Importance6=ImportanceAge
	gen Importance7=ImportanceEthnicity

	gen Undeserving2=UndeservingWorkingClass
	gen Undeserving3=UndeservingRural
	gen Undeserving4=UndeservingNonuniv
	gen Undeserving5=UndeservingWomen
	gen Undeserving6=UndeservingElderly
	gen Undeserving7=UndeservingEthnic

	gen LikeGroup2=LikeWorkingClass
	gen LikeGroup3=LikeRural
	gen LikeGroup4=LikeNonuniv
	gen LikeGroup5=LikeWomen
	gen LikeGroup6=LikeElderly
	gen LikeGroup7=LikeEthnic

	reshape long Candidate CandidateAll Vignette Ingroup Importance Undeserving LikeGroup OrderVignette LabourVignette, i(caseid) j(number)  

	gen appeal=1 if arm_treatment==2		// assigned to an appeal
	replace appeal=0 if arm_treatment==1	// assigned to control

	gen SharedPartisan=0			
	replace SharedPartisan=1 if LabourVignette==1 & profile_partyid==2	// labour partisans
	replace SharedPartisan=1 if LabourVignette==0 & profile_partyid==1	// conservative partisans 

	gen PID3groups=0 if profile_partyid==6								// non-partisan 
	replace PID3groups=1 if SharedPartisan==1							// partisan candidate's party
	replace PID3groups=2 if SharedPartisan!=1 & profile_partyid<=5		// partisan other party

	gen Deserving=0 if Undeserving==10
	replace Deserving=1 if Undeserving==9
	replace Deserving=2 if Undeserving==8
	replace Deserving=3 if Undeserving==7
	replace Deserving=4 if Undeserving==6
	replace Deserving=5 if Undeserving==5
	replace Deserving=6 if Undeserving==4
	replace Deserving=7 if Undeserving==3
	replace Deserving=8 if Undeserving==2
	replace Deserving=9 if Undeserving==1
	replace Deserving=10 if Undeserving==0
	
	** generate generic group appeal variable
	gen appeal3groups=1 if appeal==1 & Ingroup==0		// outgroup appeal as the reference
	replace appeal3groups=2 if appeal==1 & Ingroup==1	// ingroup appeal
	replace appeal3groups=3 if appeal==0
	
	label define appeal3groupslabel 1 "Outgroup appeal" 2 "Ingroup appeal" 3 "No group appeal"
	label values appeal3groups appeal3groupslabel

	** analyse data while removing non-partisans and the control condition for appeals (i.e. there always is an in-group or an out-group for parties and groups)
	eststo m1: reg CandidateAll i.appeal3groups b2.PID3group SuccesAttention if appeal==1 & PID3group!=0, cluster(caseid)
	
	esttab m1 using appendixUtable.tex, b(3) se(3) r2 nogap  replace

	
	
	
	
	